package com.tanhua.app.controller;

import com.tanhua.app.controllerservice.VideoService;
import com.tanhua.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class VideoController {

    @Autowired
    private VideoService videoService;

    @GetMapping(name = "分页展示小视频内容",value = "/smallVideos")
    public ResponseEntity smallVideos(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize){

        if(page==0){
            page=1;
        }
        PageBeanVo pageBeanVo = videoService.smallVideos(page, pagesize);

        return ResponseEntity.ok(pageBeanVo);
    }

    @PostMapping(name = "小视频上传",value = "/smallVideos")
    public ResponseEntity toSmallVideos(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {

        return videoService.toSmallVideos(videoThumbnail,videoFile);
    }



    @PostMapping(name = "小视频作者的关注",value = "/smallVideos/{uid}/userFocus")
    public ResponseEntity userFocus(@PathVariable("uid") Integer vid) throws IOException {

        return videoService.userFocus(vid);
    }


    @PostMapping(name = "小视频作者的关注撤销",value = "/smallVideos/{uid}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("uid") Integer vid) throws IOException {

        return videoService.userUnFocus(vid);
    }


}
